package com.bruce.starts.demo.goodcode.utils;

import org.apache.commons.collections4.bag.HashBag;
import org.junit.Assert;
import org.junit.Test;

import java.util.Random;

public class CommonUtils {
    /**
     * 生产随机位数的字符
     * @param size
     * @return
     */
    public String generatorRandomCode(int size) {
        return new Random().ints(48, 122)
                .filter(i -> (i < 57 || i > 65) && (i < 90 || i > 97))
                .mapToObj(i -> (char) i)
                .limit(size)
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
                .toString();
    }
    @Test
    public void testGeneratorCode(){
        String result = generatorRandomCode(4);
        System.out.println(result);
        Assert.assertEquals(4, result.length());
    }
    @Test
    public void testBag(){
        HashBag<String> bags = new HashBag<>();
        bags.add("bruce");
        bags.add("bruce2");
        bags.add("bruce");
        System.out.println(bags.getCount("bruce"));
    }
}
